package cn.lili.controller.promotion;

import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.Ticket;
import cn.lili.modules.promotion.entity.dos.TicketPoll;
import cn.lili.modules.promotion.entity.dos.TicketPollRecord;
import cn.lili.modules.promotion.service.TicketPollRecordService;
import cn.lili.modules.promotion.service.TicketPollService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Api(tags = "门票嘉宾接口")
@RequestMapping("/promotion/ticket/poll")
@RequiredArgsConstructor
public class TicketPollController {
    private final TicketPollService ticketPollService;

    private final TicketPollRecordService ticketPollRecordService;

    @ApiOperation(value = "查询嘉宾列表")
    @GetMapping
    public ResultMessage<List<TicketPoll>> getByList(String pollName, HttpServletRequest request) {
        return ResultUtil.data(ticketPollService.getList(pollName, request));
    }

    @ApiOperation(value = "添加嘉宾")
    @PostMapping("/addTicketPoll")
    public ResultMessage<Void> addTicketPoll(@RequestBody TicketPoll ticketPoll) {
        ticketPollService.addTicketPoll(ticketPoll);
        return ResultUtil.success();
    }

    @ApiOperation(value = "增加嘉宾票数")
    @GetMapping("/addPoll/{id}")
    public ResultMessage<List<Void>> addPoll(@PathVariable String id, Integer numbers) {
        ticketPollService.addPoll(id, numbers);
        return ResultUtil.success();
    }

    @ApiOperation(value = "获取用户当天投票数据")
    @GetMapping("/getByUserId")
    public ResultMessage<List<TicketPollRecord>> getByUserId() {
        return ResultUtil.data(ticketPollRecordService.getByUserId());
    }

    @ApiOperation(value = "用户投票接口")
    @GetMapping("/add/{pollId}")
    public ResultMessage<Void> add(@PathVariable String pollId) {
        ticketPollRecordService.add(pollId);
        return ResultUtil.success();
    }
}
